Artificial Intelligence for Humans, Volume 2: Nature-Inspired Algorithms by Jeff Heaton

Artificial Intelligence for Humans, Volume 2: Nature-Inspired Algorithms by Jeff Heaton

Author:Jeff Heaton
Language: eng
Format: mobi, epub
Publisher: Heaton Research, Inc.
Published: 2014-08-22T00:00:00+00:00


Tree Crossover

Tree crossover allows two parent trees to reproduce sexually. Crossover works by copying parent 1, and then it grafts a copied portion of parent 2 into the copy of parent 1. Neither parent is altered in this process. Listing 4.8 shows the pseudocode to implement crossover.

Listing 4.8: Tree Crossover Pseudocode

sub tree_crossover(parent1, parent2):

# Find a random point in parent 2,

# we will copy this to the new child.

source = sample_node(parent2.root)

# Create the child as a clone of parent 1.

child = parent1.clone()

# Find a random point in the child to graft in parent 2 point.

target = sample_node(child.root)

# Replace at the child's random point with a

#clone of parent 2's point.

child.replace(target,source.clone())

return child



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.